package gtfaces;

import java.util.*;

public class RunResults {

	private Map<String, List<TSquareImage>> successful;
	private Map<String, List<TSquareImage>> failure;
	private Map<String, IntPair> classResults;
	private String userName;
	
	public Map<String, List<TSquareImage>> getSuccessful() {
		return successful;
	}

	public Map<String, List<TSquareImage>> getFailure() {
		return failure;
	}

	public Map<String, IntPair> getClassResults() {
		return classResults;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public RunResults(String userName) {
		this.userName = userName;
		successful = new HashMap<String, List<TSquareImage>>();
		failure = new HashMap<String, List<TSquareImage>>();
		classResults = new HashMap<String, IntPair>();
	}
	
	public boolean addSuccess(String className, TSquareImage img) {
		if (!successful.containsKey(className))
			successful.put(className, new LinkedList<TSquareImage>());
		if (!successful.get(className).contains(img)) {
			successful.get(className).add(img);
			return true;
		}
		return false;
	}
	
	public boolean addFailure(String className, TSquareImage img) {
		if (!failure.containsKey(className))
			failure.put(className, new LinkedList<TSquareImage>());
		if (!failure.get(className).contains(img)) {
			failure.get(className).add(img);
			return true;
		}
		return false;
	}
	
	public boolean addClassResults(String className, int total, int successful) {
		if (classResults.get(className) == null)
			classResults.put(className, new IntPair(total, successful));
		return false;
	}
	
	public static class IntPair {
		public int total;
		public int successful;
		public IntPair(int total, int successful) {
			this.total = total;
			this.successful = successful;
		}
		@Override
		public String toString() {
			return successful + "/" + total;
		}
	}
	
	public String getRatioString(String className) {
		return classResults.get(className) == null ? "" : classResults.get(className).toString();  
	}
	
	public String getSuccessString(String className) {
		if (getRatioString(className) == null || getRatioString(className).length() == 0)
			return "Error processing " + className;
		return getRatioString(className) + " added successfully from " + className;
	}
}
